package com.aspose.cells;

import java.io.IOException;
import java.io.InputStream;

class zcfz {
   protected zcgb a;
   protected int b;
   protected int c;
   protected byte[] d;
   protected byte[] e;
   protected boolean f;
   protected InputStream g;
   private boolean h;

   public zcfz(InputStream var1) {
      this(var1, false);
   }

   public zcfz(InputStream var1, boolean var2) {
      this.a = new zcgb();
      this.b = 512;
      this.c = 0;
      this.d = new byte[this.b];
      this.e = new byte[1];
      this.g = null;
      this.h = false;
      this.g = var1;
      this.a.a(var2);
      this.f = false;
      this.a.a = this.d;
      this.a.b = 0;
      this.a.c = 0;
   }

   public int a(byte[] var1, int var2, int var3) throws IOException {
      if (var3 == 0) {
         return 0;
      } else {
         this.a.e = var1;
         this.a.f = var2;
         this.a.g = var3;

         int var4;
         do {
            if (this.a.c == 0 && !this.h) {
               this.a.b = 0;
               this.a.c = this.g.read(this.d, 0, this.b);
               if (this.a.c == -1) {
                  this.a.c = 0;
                  this.h = true;
               }
            }

            if (this.f) {
               var4 = this.a.b(this.c);
            } else {
               var4 = this.a.a(this.c);
            }

            if (this.h && var4 == -5) {
               return -1;
            }

            if (var4 != 0 && var4 != 1) {
               throw new IOException((this.f ? "de" : "in") + "flating: " + this.a.i);
            }

            if ((this.h || var4 == 1) && this.a.g == var3) {
               return -1;
            }
         } while(this.a.g == var3 && var4 == 0);

         return var3 - this.a.g;
      }
   }
}
